package com.elinkway.infinitemovies.http.parser;

import com.elinkway.infinitemovies.bean.RankItem;
import com.elinkway.infinitemovies.bean.RankList;

import org.json.JSONArray;
import org.json.JSONObject;

public class RankListParser extends LVideoMobileParser<RankList> {
	private static final String SORT = "sort";
	private static final String NAME = "name";
	private static final String THEMEID = "themeid";
	private static final String PIC = "pic";
	private static final String VIDEOTYPE = "vt";
	private static final String ALBUMID = "aid";
	private static final String SUBNAME = "subname";
	private static final String PLAYURL = "playurl";
	private static final String PLAYSITE = "playsite";
	private static final String SCORE = "rating";
	
	
	private static final String DATA = "data";
	@Override
	public RankList parse(JSONObject data) throws Exception {
		// TODO Auto-generated method stub
		RankList children=new RankList();
		data = data.getJSONObject(DATA);
		children.setVt(data.optString("vt"));
		children.setName(data.optString("rankname"));
		if (data.has(DATA)){
			JSONArray arr = data.getJSONArray(DATA);
			for (int i=0;i<arr.length();i++){
				RankItem childItem = new RankItem();
				JSONObject childObj = arr.getJSONObject(i);
				childItem.setIsend(childObj.optString("isend"));
				childItem.setNowepisodes((childObj.optString("nowepisodes")));
				if (childObj.has(SORT)){
					childItem.setSort(childObj.getString(SORT));
				    }
				if (childObj.has(NAME)){
					childItem.setName(childObj.getString(NAME));
				    }
				if (childObj.has(THEMEID)){
					childItem.setThemeid(childObj.getString(THEMEID));
				    }
				if (childObj.has(PIC)){
					childItem.setPic_m_horse(childObj.getString(PIC));
				    }
				if (childObj.has(VIDEOTYPE)){
					childItem.setVt(childObj.getString(VIDEOTYPE));
				    }
				if (childObj.has(ALBUMID)){
					childItem.setAlbumid(childObj.getString(ALBUMID));
				    }
				if (childObj.has(SUBNAME)){
					childItem.setSubname(childObj.getString(SUBNAME));
				    }
				if (childObj.has(PLAYURL)){
					childItem.setPlayurl(childObj.getString(PLAYURL));
				    }
				if (childObj.has(PLAYSITE)){
					childItem.setPlaysite(childObj.getString(PLAYSITE));
				    }
				if (childObj.has(SCORE)){
					childItem.setRating(childObj.getString(SCORE));
				}
				children.getRankList().add(childItem);
			}
		}
		return children;
		
		
	}
}
